home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.07 Jul 90 / Commando Programming ƒ / Rezscripts / NewTempFile < prev    next >
Encoding:
Text File  |  1988-07-28  |  2.1 KB  |  97 lines  |  [TEXT/MPS ]

  1. ###        NewTempFile — Open a window on a new temporary file.
  2. ###            W. Powell, 1988
  3. ###        Automatically insures unique file names.
  4.  
  5. Set Exit 0
  6. Set TargMode 0
  7. Set EchoMode 0
  8. Unset BaseName
  9. Set NameIn 0
  10. Set ErrGen 0
  11. # Check calling arguments
  12. If {#} > 3 
  13.     Echo "### NewTempFile — bad arguments" >>Dev:StdErr
  14.     Echo "###     NewTempFile [-t] [-e | -q] [basename] " >>Dev:StdErr
  15.                 Exit 1
  16. End
  17. # Use the arguments
  18. If {#} > 0
  19.     For NewArg In {"Parameters"}
  20.         If "{NewArg}" == "-t"
  21.             Set TargMode 1
  22.         Else If "{NewArg}" == "-e"
  23.             If {EchoMode}
  24.                 Echo "### NewTempFile - only one of -e, -q allowed" >>Dev:StdErr
  25.                 Echo "###     NewTempFile [-t] [-e | -q] [basename] " >>Dev:StdErr
  26.                 Exit 1
  27.             Else
  28.                 Set EchoMode 1
  29.                 Set Quote 0
  30.             End
  31.         Else If "{NewArg}" == "-q"
  32.             If {EchoMode}
  33.                 Echo "### NewTempFile - only one of -e, -q allowed" >>Dev:StdErr
  34.                 Echo "###     NewTempFile [-t] [-e | -q] [basename] " >>Dev:StdErr
  35.                 Exit 1
  36.             Else
  37.                 Set EchoMode 1
  38.                 Set Quote 1
  39.             End
  40.         Else
  41.             If {NameIn}
  42.                 Echo "### NewTempFile — bad arguments" >>Dev:StdErr
  43.                 Echo "###     NewTempFile [-t] [-e | -q] [basename] " >>Dev:StdErr
  44.                 Exit 1
  45.             Else
  46.                 Set NameIn 1
  47.                 Set BaseName "{NewArg}"
  48.             End
  49.         End
  50.     End
  51. End
  52. # If basename not specified, use this default
  53. If ¬ {NameIn}
  54.     Set BaseName TEMPzs
  55. End
  56. Unset NameIn
  57.  
  58. #  Note:  Directory for temp files defined by variable
  59. #         {TMP} defined in Startup script
  60. Set TmpCnt `Files "{TMP}" | Count -l`
  61. Set TmpCnt `Evaluate {TmpCnt} + 1 `
  62.  
  63. #    Create a unique new Temporary File
  64. Loop    # Until unique new file is opened
  65.     # Trial filename
  66.     Set uniq "{TMP}{BaseName}{TmpCnt}"
  67.     # Try to create file
  68.     If "{uniq}" == `Exists -f "{uniq}" `
  69.         # Not a unique name, so
  70.         # Increment and try again
  71.         Set TmpCnt `Evaluate {TmpCnt} + 1 `
  72.     Else
  73.         # Found a good file name, try to open it.
  74.         New "{uniq}"
  75.         Set NewStat {Status}
  76.         If {NewStat}
  77.             Echo "### NewTempFile terminated" ≥≥Dev:StdErr
  78.             Exit {NewStat}
  79.         End
  80.         If {TargMode}
  81.             Open -t "{uniq}"
  82.         End
  83.         If {EchoMode}
  84.             If {Quote}
  85.                 Quote "{uniq}"
  86.             Else
  87.                 Echo "{uniq}"
  88.             End
  89.         End
  90.         Break # out of this loop
  91.     End
  92. End
  93. # Successful, Window is open
  94. Exit 0
  95.  
  96. ### End file NewTempFile
  97. ##############################